<?php

namespace module\manage\controller;

use app\Controller;
use app\model\Activity as Model;

class Activity extends Controller
{
    /**
     * 列表.
     * 
     */
    public function index()
    {
        $result = Model::with(['user'])->withSearch(['user_id', 'status', 'title'], input('get.'))->paginate([
            'list_rows'=> input('get.pageSize/d', 10),
        ]);
        return json([
            'items' => $result->items(),
            'total' => $result->total(),
        ]);
    }
    /**
     * 详情.
     * 
     * @param int $id
     */
    public function read(int $id)
    {
        $model = Model::with(['detail', 'user', 'album', 'workers'])->findOrFail($id);
        return json($model->toArray());
    }
    /**
     * 更新.
     * 
     * @param int $id
     */
    public function update(int $id)
    {
        $model = Model::findOrfail($id);
        $model->save($this->request->put());
        return json($model->toArray());
    }
    /**
     * 删除.
     * 
     * @param int $id
     */
    public function del(int $id)
    {
        $model = Model::findOrFail($id);
        $model->delete();
        return json($model->toArray());
    }
    /**
     * 状态.
     * 
     * @param int $id
     */
    public function status(int $id)
    {
        $model = Model::findOrFail($id);
        $model->status = [1, 0][$model->status];
        $model->save();
        return json($model->toArray());
    }
}
